Raspberry Pi LED Blueprints by Agus Kurniawan

Raspberry Pi LED Blueprints by Agus Kurniawan

Author:Agus Kurniawan
Language: eng
Format: epub
Publisher: Packt Publishing


Here is the explanation:

First, define the initial position and speed

Set the ball speed vx = 1 and vy = 2

A ball moves by adding its position to the current position with vx and vy

Define the draw_ball() function to draw a ball on the 8 x 8 dot matrix display based on the current position of ball

Since the 8 x 8 LED dot matrix display has eight points, we should validate the pos_x and pos_y values with the following validation:

if pos_x >= 7: direction = -1 if pos_x <= 0: direction = 1

This code uses global variables. You can read another approach to use local variables for pos_x, pos_y, last_x, and last_y. Please open the ch04_o4b.py file.

Save this code. Execute the program by typing the following command:

sudo python ch04_04.py



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.